package com.enjoy.basic.serializable;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.msgpack.MessagePack;

/**
 * 序列化机制
 * Created by HP on 2019/7/15.
 */
public class MsgPackEncode extends MessageToByteEncoder<Object>{
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Object o, ByteBuf byteBuf) throws Exception {
        MessagePack messagePack=new MessagePack();
        byte[] raw =messagePack.write(o);
        byteBuf.writeBytes(raw);
    }
}
